package com.yxj03;

import java.io.*;

public class BufferStreamDemo {
    public static void main(String[] args) throws IOException {
/*        //字节缓冲输出流：BufferOutputStream(OutputStream out)
//        FileOutputStream fos = new FileOutputStream("D:\\Ccode\\jdata-structure\\ByteStream9\\bos.txt");
//        BufferedOutputStream bos = new BufferedOutputStream(fos);
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\Ccode\\jdata-structure\\ByteStream9\\bos.txt"));
        //写数据
        bos.write("hello\r\n".getBytes());
        bos.write("world\r\n".getBytes());
        bos.close();*/


        //字节缓冲输入流：BufferInputStream(InputStream in)
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\Ccode\\jdata-structure\\ByteStream9\\bos.txt"));
        //方式1：一次读取一个字节数据
/*        int by;
        while((by=bis.read()) != -1) {
            System.out.print((char)by);
        }*/

        //方法2：一次读取一个字节数组数据
        byte[] bytes = new byte[1024];
        int len;
        while((len=bis.read(bytes)) != -1) {
            System.out.println(new String(bytes,0,len));
        }
        bis.close();
    }
}
